﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Trade.DAL;
using Trade.Model;

namespace Trade
{
    public partial class FrmLogin : Form
    {
        public FrmLogin()
        {
            InitializeComponent();
            this.txtUserID.Focus();
        }

        private void CancelBtn_Click(object sender, EventArgs e)
        {
            //this.Close();
            Application.Exit();
        }

        private void ApplyBtn_Click(object sender, EventArgs e)
        {
            string userId = this.txtUserID.Text.Trim();
            string pwd = this.txtPassword.Text.Trim();
            UserInfo loginUser = null;

            if (userId.Length == 0 || pwd.Length == 0)
            {
                MessageBox.Show("请输入用户名和密码!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.txtUserID.Focus();
                return;
            }

            loginUser = User.ValidateLogin(userId, pwd);

            if (loginUser != null)
            {
                FrmMain.curUserEnvir.userBaseData = loginUser;
                FrmMain.login = true;
                //MessageBox.Show(MainForm.curUserEnvir.userBaseData.UserName);
                this.Close();
            }
            else
            {
                MessageBox.Show("用户名或密码错误!!!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }

        private void LoginForm_Load(object sender, EventArgs e)
        {

        }

        protected override bool ProcessDialogKey(Keys keyData)
        {
            if (keyData == Keys.Enter && this.ActiveControl is TextBox)
            {
                keyData = Keys.Tab;
            }
            return base.ProcessDialogKey(keyData);
        }
    }
}
